pre_install() {
	echo "Cleaning any old chroots before installing a new one..."
        if [ -d '/srv/nginxchroot' ]; then
	  umount /srv/nginxchroot/tmp
	  umount /srv/nginxchroot/var/run
	  rm -rf /srv/nginxchroot
	fi
}

post_install() {
	echo "Installing a new chroot ... "
	/bin/sh -c "/usr/libexec/nginx-hardened-scripts/nginxchroot.sh"
	wait
	echo "Done!"
	echo "====="
	echo "To use this service please disable nginx,"
	echo "then enable nginx-hardened via HyperRC or runit."
	echo "====="
}

post_upgrade() {
        echo "Stopping chrooted nginx..."
        if [ -x /etc/init.d/nginx-hardened ]; then
	  /etc/init.d/nginx-hardened stop
	fi
	 
	echo "Cleaning old chroot and putting in a new one..."
        if [ -d '/srv/nginxchroot' ]; then
	  umount /srv/nginxchroot/tmp
	  umount /srv/nginxchroot/var/run
	  rm -rf /srv/nginxchroot
	fi
	wait
	/bin/sh -c "/usr/libexec/nginx-hardened-scripts/nginxchroot.sh"
	wait
	echo "Done!"
	echo "====="
	echo "To use this service please disable nginx,"
	echo "then enable nginx-hardened via HyperRC or runit."
	echo "====="
}

pre_remove() {
         echo "Stopping chrooted nginx..."
         if [ -x /etc/init.d/nginx-hardened ]; then
	   /etc/init.d/nginx-hardened stop
	 fi
}

post_remove() {
	echo "Deleting chroot..."
        if [ -d '/srv/nginxchroot' ]; then
	  umount /srv/nginxchroot/tmp
	  umount /srv/nginxchroot/var/run
	  rm -rf /srv/nginxchroot
	fi
	wait
	echo "Done!"
}
